<?php

/**
 * 这是一个表 "sms_log" 的模型类。
 *
 * 表 'sms_log' 有以下字段:
 * @property integer $id
 * @property integer $activity_id
 * @property integer $sms_type
 * @property string $name
 * @property string $phone
 * @property string $send_time
 * @property string $sms_content
 *
 * 以下是表的关联关系:
 * @property Activity $activity
 */
class SmsLog extends CActiveRecord
{
	/**
	 * @return string 表名
	 */
	public function tableName()
	{
		return 'sms_log';
	}

	/**
	 * @return array 表字段验证规则的数组。
	 */
	public function rules()
	{
		return array(
			array('activity_id, sms_type', 'numerical', 'integerOnly'=>true),
			array('name, phone', 'length', 'max'=>20),
			array('send_time, sms_content', 'safe'),
			// 以下规则用于验证查询函数，如果不做查询可注释此行。
			array('id, activity_id, sms_type, name, phone, send_time, sms_content', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array 关联关系。
	 */
	public function relations()
	{
		return array(
			'activity' => array(self::BELONGS_TO, 'Activity', 'activity_id'),
		);
	}

	/**
	 * @return array 自定义字段显示文本标签 (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => '主键',
			'activity_id' => '活动名称',
			'sms_type' => '短信类型',
			'name' => '收件人姓名',
			'phone' => '收件人手机号',
			'send_time' => '发送时间',
			'sms_content' => '短信内容',
		);
	}

	/**
	 * 自定义查询函数
	 * @return CActiveDataProvider 一个包含分页排序查询数据
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('activity_id',$this->activity_id);
		$criteria->compare('sms_type',$this->sms_type);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('send_time',$this->send_time,true);
		$criteria->compare('sms_content',$this->sms_content,true);
		$criteria->order='id desc';//排序字段

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
                'pageSize'=>Yii::app()->params['pagesize'],//配置文件中设置过分页条数
            ),
		));
	}
	public function search_activty($activity_ids)
	{
		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
//		$criteria->compare('activity_id',$this->activity_id);
		$criteria->compare('sms_type',$this->sms_type);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('send_time',$this->send_time,true);
		$criteria->compare('sms_content',$this->sms_content,true);
		$criteria->order='id desc';//排序字段
                $criteria->addInCondition('activity_id', $activity_ids);
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
                'pageSize'=>Yii::app()->params['pagesize'],//配置文件中设置过分页条数
            ),
		));
	}
	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return SmsLog the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
